package base.template;

import java.util.ArrayList;
import java.util.Random;

class Product {
	private final int id;
	private String des;
	private double price;

	public Product(int id, String des, double price) {
		this.id = id;
		this.des = des;
		this.price = price;
		System.out.println(toString());
	}

	public String toString() {
		return id + ": " + des + ", price: $" + price;
	}

	public void priceChange(double change) {
		price += change;
	}

	public static Generator<Product> generator = new Generator<Product>() {

		private Random rand = new Random();

		public Product next() {
			return new Product(rand.nextInt(1000), "test", Math.round(rand
					.nextDouble() * 1000.0) + 0.99);
		}
	};
}

@SuppressWarnings("serial")
class Shelf extends ArrayList<Product> {
	public Shelf(int nProducts) {
		Generators.fill(this, Product.generator, nProducts);
	}
}

@SuppressWarnings("serial")
class Aisle extends ArrayList<Shelf> {
	public Aisle(int nShelves, int nProducts) {
		for (int i = 0; i < nShelves; i++) {
			add(new Shelf(nProducts));
		}
	}
}

@SuppressWarnings("serial")
public class Store extends ArrayList<Aisle>{

	public Store(int  nAisles,int nShelves,int nProducts){
		for(int i=0;i<nAisles;i++){
			add(new Aisle(nShelves, nProducts));
		}
	}
	
	public String toString(){
		StringBuilder builder=new StringBuilder();
		for(Aisle a:this){
			for(Shelf s:a){
				for(Product p:s){
					builder.append(p);
					builder.append("\n");
				}
			}
		}
		return builder.toString();
	}
	public static void main(String[] args) {
		System.out.println(new Store(14,5,10));
	}
	
}
